package com.cskaoyan.controller;



import com.cskaoyan.bean.Topic;
import com.cskaoyan.service.TopicService;
import com.cskaoyan.vo.BaseRespVo;
import com.cskaoyan.vo.TopicVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TopicController {
    @Autowired
    TopicService topicService;
    //显示专题列表
    @RequestMapping("admin/topic/list")
    public BaseRespVo topicList(Integer page, Integer limit, String sort, String order,String title,String subtitle){
        //查询
        if ((title != null && title != "") || (subtitle != null && subtitle != "")){
            TopicVo topicVo = topicService.queryTopic(page,limit,sort,order,title,subtitle);
            return BaseRespVo.ok(topicVo);
        }
        TopicVo topicVo = topicService.topicList(page,limit,sort,order);
        return BaseRespVo.ok(topicVo);
    }
    //删除列表
    @RequestMapping("admin/topic/delete")
    public BaseRespVo deleteTopic(@RequestBody Topic topic){
        int ant = topicService.deleteTopic(topic);
        return BaseRespVo.ok();
    }
    //更新列表
    @RequestMapping("admin/topic/update")
    public BaseRespVo updateTopic(@RequestBody Topic topic){
        Topic top = topicService.updateTopic(topic);
        return BaseRespVo.ok(top);
    }
    @RequestMapping("admin/topic/create")
    public BaseRespVo addCreate(@RequestBody Topic topic){
        Topic as = topicService.addCreate(topic);
        return BaseRespVo.ok(as);
    }
}
